﻿<%@ Page Language="C#" AutoEventWireup="true" Buffer="false" CodeBehind="DesktopConfigForAdmin.aspx.cs" Inherits="ZX.WebApp.DeskTop.Form.DesktopConfigForAdmin" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    <link href="styles/css.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/CustomFunction.js" type="text/javascript"></script>
    <script src="Scripts/json2.js" type="text/javascript"></script>
    <script src="../../KM/FullTextSearch/Script/CommonJS.js" type="text/javascript"></script>
    <link href="../../Styles/deskTopStyle.css" rel="stylesheet" type="text/css" />

    <script src="Scripts/artDialog4.1.6/artDialog.js?skin=default"></script>
    <script src="Scripts/artDialog4.1.6/plugins/iframeTools.js" type="text/javascript"></script>
    <script src="Scripts/Guid.js" type="text/javascript"></script>

    <style type="text/css">
        .pos_abs
		{
		    font-size:11pt;
            position: fixed;
            color:#fff; 
            background-color:#A4D3EE;
            vertical-align:top;
            width:100%;
            text-align:center;
            opacity: 0.7;
            -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
            filter: alpha(opacity=70);
            -moz-opacity: 0.7;
            -khtml-opacity: 0.7;
            z-index:99;
		}
    </style>
</head>
<body>
    <div class="pos_abs">
        <input type="button" id="btnAdd" value="新增" />&nbsp;&nbsp;
        <input type="button" id="btnSave" value="保存" />&nbsp;&nbsp;
        <input type="checkbox" id="selectAll" value="全选" />
    </div>
    <div style="height:25px;">&nbsp;</div>
    <!--主体 开始-->
    <div class="custom_clum_box">
        <!--左边框-->
        <div class="custom_clum_left_small" style="width:50%;"></div>

        <!--右边框-->
        <div class="custom_clum_right_small" style="width:50%;"></div>
    </div>
    <!--主体 结束-->
</body>
</html>

<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
<%--<script type="text/javascript" src="Scripts/jquery.sortable.js"></script>--%>
<script type="text/javascript">

    var RoleID = getQueryStringByName("RoleID");
    var custom_clum_left = $(".custom_clum_left_small"); //左边容器
    var custom_clum_right = $(".custom_clum_right_small"); //右边容器

    //  ID： clum_tools_reload_+ id  刷新按钮
    var refreshBtn_Html = "<li class='ul_li_buttons refresh' style='width:25px;'><img class='clum_tools_reload' src='styles/images/refresh.png' /></li>";
    //  ID：clum_tools_more_+id      更多按钮
    var moreBtn_Html = "<li class='ul_li_buttons more' style='width:45px;color:#6CA6CD;'><a class='clum_tools_more' >更多..<a/></li>";

    $(function () {
        RoleID = getQueryStringByName("RoleID");
        custom_clum_left = $(".custom_clum_left_small");
        custom_clum_right = $(".custom_clum_right_small");
        custom_clum_left.html(""); custom_clum_right.html("");

        loadData();

        //动态注册tab按钮事件   Tab按钮
        $(".tab").live("click", function () {
            changeTab($(this));
        });
        //新增
        $("#btnAdd").click(function () {
            openWindow('', '', '999', 'add', $(this));
        });
        //修改
        $(".class_btnEdit").live("click", function () {
            var RoleDesktopID = $(this).attr("RoleDesktopID");
            var DeskTopTempID = $(this).attr("DeskTopTempID");
            var sort = $(this).attr("sort");
            $(".clum_big_center_small").css("background-color", "#FFFFFF");
            $(this).parent().parent().css("background-color", "#CAE1FF");
            openWindow(DeskTopTempID, RoleDesktopID, sort, 'edit', $(this));
        });
        //删除
        $(".class_btnDel").live("click", function () {
            var DeskTopTempID = $(this).attr("DeskTopTempID");
            $(".clum_content_small").css("background-color", "#FFFFFF");
            $(this).parent().parent().css("background-color", "#CAE1FF");
            var delObj = $(this);
            var msg = "您真的确定要删除吗？\n\n该操作将做一下几个操作：\n\n1、删除桌面模板数据\n\n2、角色桌面数据\n\n3、用户自定义桌面数据。";
            if (confirm(msg) == true) {
                $.post("DesktopConfigForAdmin.aspx?Action=Delete&DeskTopTempID=" + DeskTopTempID + "&r=" + Math.random(), function (data) {
                    if (data) {
                        delObj.parent().parent().parent().parent().parent().parent().remove();
                        alert("删除成功!");
                    }
                    else {
                        alert("删除失败");
                    }
                });
            } else {
                return false;
            }
        });

        $(".class_radio").live("click", function () {
            var radio = $(this).find(".class_radio");
            $(".class_radio").attr("mouseup", "false");
            radio.attr("checked", "true");
        });

        $(".moveUp,.moveDown,.moveTop,.moveBottom").live("click", function () {
            var event = $(this);
            var p = event.parent().parent().parent().parent().parent().parent();
            var title = event.attr("ct");
            $(".clum_content_small").css("background-color", "#FFFFFF");
            event.parent().parent().css("background-color", "#CAE1FF");
            switch (title) {
                case "top":
                    c_top(p);
                    break;
                case "bottom":
                    c_bottom(p);
                    break;
                case "up":
                    c_pre(p);
                    break;
                case "down":
                    c_next(p);
                    break;
            }
        });

        $("#selectAll").click(function () {
            var ck = $(this).attr("checked");
            if (ck) $("input:checkbox[name='selectCheckbox']").attr("checked", ck);
            else $("input:checkbox[name='selectCheckbox']").removeAttr("checked");
        });

        $("input:checkbox[name='selectCheckbox']").live("click", function () {
            var ckObj = $(this);
            var p = ckObj.parent().parent().parent().parent().parent().parent();
            var ck = ckObj.attr("checked");
            if (ck) {
                c_top(p);
            }
            else {
                ckObj.removeAttr("checked");
                c_bottom(p);
            }
        });

        $("#btnSave").click(function () {
            saveData();
        });
    });

    //上移
    var c_pre = function (o) {
        var o = $(o).parent();
        if (o.prev().length > 0) {
            var tmp = o.clone();
            var oo = o.prev();
            o.remove();
            oo.before(tmp);
        }
    };
    //下移
    var c_next = function (o) {
        var o = $(o).parent();
        if (o.next().length > 0) {
            var tmp = o.clone();
            var oo = o.next();
            o.remove();
            oo.after(tmp);
        }
    };
    //左移
    var c_left = function (o) {
        var o = $(o).parent();
        var tmp = o.clone();
        o.remove();
        custom_clum_left.append(tmp);
    }
    //右移
    var c_right = function (o) {
        var o = $(o).parent();
        var tmp = o.clone();
        o.remove();
        custom_clum_right.append(tmp);
    }
    //置顶
    var c_top = function (o) {
        var o = $(o).parent();
        if (o.prev().length > 0) {
            var tmp = o.clone();
            var oo = o.parent().find(".list_panel_small:first");
            o.remove();
            oo.before(tmp);
        }
    };
    //置底
    var c_bottom = function (o) {
        var o = $(o).parent();
        if (o.next().length > 0) {
            var tmp = o.clone();
            var oo = o.parent().find(".list_panel_small:last");
            o.remove();
            oo.after(tmp);
        }
    };
    //保存
    var saveData = function () {
        var leftObj = custom_clum_left.find("input:checkbox[name='selectCheckbox']:checked");
        var rightObj = custom_clum_right.find("input:checkbox[name='selectCheckbox']:checked");

        var Data = [];
        $.each(leftObj, function (i, m) {
            var mObj = $(m);

            var id = mObj.attr("DeskTopTempID");

            var RoleDesktopID = mObj.attr("RoleDesktopID");
            if (RoleDesktopID == "" || RoleDesktopID == null) RoleDesktopID = Guid.NewGuid().ToString();

            var RoleID = mObj.attr("RoleID");
            var sort = Number(i) + Number(1);

            var temp = { id: id, RoleDesktopID: RoleDesktopID, roleid: RoleID, sort: sort };
            Data.push(temp);
        });

        $.each(rightObj, function (j, mm) {
            var mObj = $(mm);

            var id = mObj.attr("DeskTopTempID");

            var RoleDesktopID = mObj.attr("RoleDesktopID");
            if (RoleDesktopID == "" || RoleDesktopID == null) RoleDesktopID = Guid.NewGuid().ToString();

            var RoleID = mObj.attr("RoleID");
            var sort = Number(j) + Number(1);

            var temp = { id: id, RoleDesktopID: RoleDesktopID, roleid: RoleID, sort: sort };
            Data.push(temp);
        });

        Data = JSON2.stringify(Data);

        $.post("DesktopConfigForAdmin.aspx?Action=Save&Data=" + Data + "&roleID=" + RoleID + "&r=" + Math.random(), function (data) {
            if (data) {
                alert("保存成功!");
                window.location.reload();
            }
            else {
                alert("保存失败");
            }
        });
    };


    //tab切换事件，更改tab焦点
    var changeTab = function (event) {
        event.parent().find("li").each(function () {
            $(this).removeClass("ul_li_active");
        })
        event.addClass("ul_li_active");
    };

    var loadData = function () {
        $.getJSON("DesktopConfigForAdmin.aspx?Action=LoadData&RoleID=" + RoleID + "&r=" + Math.random(), function (data) {
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    var m = data[i];
                    if (m.title == "输入标题1") { 
                        debugger
                    }
                    var region = m.Region;
                    createLeftPanel(m, region);
                }
            }
        });
    };

    var EditPanel = function (Data) {
        var id = Data.id;
        var Obj = $(".list_panel_small[DeskTopTempID='" + id + "']");
        if (Obj.length > 0) {
            var ck = Data.IsChecked;
            var ckStr = "";
            if (ck == "1") ckStr = "checked = 'true'";
            Obj.find(".paneltitle>.lbTitle").html(Data.title);
            Obj.find(".clum_tools>ul").html(Data.tools);
        }
    };

    //动态创建桌面
    var createLeftPanel = function (data, region) {
        var deskTopModel = "";
        var id = data.id;

        var ck = data.IsChecked;
        var ckStr = "";
        if (ck == "1") ckStr = "checked = 'true'";

        deskTopModel = "<div RoleDesktopID='" + data.RoleDesktopID + "' DeskTopTempID='" + data.id + "' RoleID='" + RoleID + "' class='list_panel_small'>" +
            "<table border='0' class='table_move' cellpadding='0' cellspacing='0' style='width:100%;height:60px;'>     " +
            "    <tr>                                                                               " +
            "        <td valign='top'><img src='styles/images/load_bk_left_small.png' /></td>       " +
            "        <td valign='top' class='clum_big_center_small'>                                " +
            "            <div class='load_title'>                                                   " +
            "                <span class='paneltitle' style='float:left;'><input type='checkbox' name='selectCheckbox' RoleDesktopID='" + data.RoleDesktopID + "' DeskTopTempID='" + data.id + "' RoleID='" + RoleID + "' id='" + data.id + "' " + ckStr + " />&nbsp;&nbsp;<label class='lbTitle'>" + data.title + "</label></span>" +
            "                <div class='clum_tools'>                                               " +
            "                    <ul>" + data.tools + "</ul>" +
            "                </div>                                                                 " +
            "            </div>                                                                     " +
            "            <div class='clum_content_small' style='text-align:right;font-size:10pt;'>  " +
            "               <span style='float:left;margin-left:25px;'><a ct='top' class='moveTop' href='javascript:void(0)'>置顶</a>&nbsp;                             " +
            "               <a ct='up' class='moveUp' href='javascript:void(0)'>上移</a>&nbsp;                             " +
            "               <a ct='down' class='moveDown' href='javascript:void(0)'>下移</a>&nbsp;                             " +
            "               <a ct='bottom' class='moveBottom' href='javascript:void(0)'>置底</a></span>" +
            "               <span style='float:right;margin-right:5px;'><a class='class_btnEdit' RoleDesktopID='" + data.RoleDesktopID + "' sort='" + data.sort + "' DeskTopTempID='" + data.id + "' RoleID='" + RoleID + "' href='javascript:void(0)'>修改</a>&nbsp;                             " +
            "               <a RoleDesktopID='" + data.RoleDesktopID + "' sort='" + data.sort + "' DeskTopTempID='" + data.id + "' RoleID='" + RoleID + "' class='class_btnDel' href='javascript:void(0)'>删除</a></span>                                   " +
            "            </div>                                                                     " +
            "        </td>                                                                          " +
            "        <td valign='top'><img src='styles/images/load_bk_right_small.png' /></td>      " +
            "    </tr>                                                                              " +
            "</table></div>";

        var deskTopModelObj = $(deskTopModel);
        var panelObj; //容器对象     
        if (region == null || region == "") region = "center"
        if (region == "center") {
            panelObj = custom_clum_left;
        } else {
            panelObj = custom_clum_right;
        }
        panelObj.append(deskTopModelObj); //容器中添加子容器
    };

    var openWindow = function (id, RoleDesktopID, sort, action, event) {

        var RoleID = getQueryStringByName("RoleID");
        var w = 780;
        var h = 255;
        var title = "新增";
        if (action != "add") title = "修改";
        var url = "DesktopConfig.aspx?Action=" + action + "&sort=" + sort + "&RoleID=" + RoleID + "&RoleDesktopID=" + RoleDesktopID + "&ID=" + id + "&ModelName=TempDeskTop&r=" + Math.random();
        art.dialog.open(url, {
            title: title,
            fixed: true,
            lock: true,
            width: w,
            height: h,
            drag: false,
            ok: function () {
                var iframe = this.iframe.contentWindow;
                if (!iframe.document.body) {
                    alert('iframe还没加载完毕呢')
                    return false;
                };
                var EditData = iframe.Modify();

                if (EditData == -1) {
                    return false;
                }

                if (EditData == false) {
                    alert("保存失败")
                    return false;
                }

                if (action == "add") {
                    var region = EditData.Region
                    createLeftPanel(EditData, region);
                } else {
                    EditPanel(EditData);
                }
                return true;
            },
            cancel: true
        });
    };
</script>